package com.trkj.controller.cf;

import java.sql.Timestamp;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.trkj.pojo.Course;
import com.trkj.pojo.Coursearrangement;
import com.trkj.pojo.OrganizationStructure;
import com.trkj.pojo.StaffInformation;
import com.trkj.pojo.Traininggactivity;
import com.trkj.service.cf.CourseService;
import com.trkj.service.cf.CoursearrangementService;
import com.trkj.service.cf.TraininggactivityService;
import com.trkj.service.wdm.StaffInformationService;
import com.trkj.vo.cf.CourseVo;
import com.trkj.vo.cf.CoursearrangementVo;

@Controller
public class ActivityContrller {
		@Autowired
		private TraininggactivityService traininggactivityService;
		@Autowired
		private CoursearrangementService coursearrangementservice;
		@Autowired
		private CourseService courseService; 
	 
		/**
		 * 培训活动
		 */
	@GetMapping("Traininggactivity_pages")
	@ResponseBody
	public Map userPage(@RequestParam("page")Integer page,@RequestParam("rows") Integer rows) {
		long total = traininggactivityService.pageCount();
		List<Traininggactivity> list = traininggactivityService.userPage(page, rows);
		Map map = new HashMap<>();
		map.put("total", total);
		map.put("rows", list);
		return map;
	}
	// 搜索
		@GetMapping("Traininggactivity_searchbox")
		@ResponseBody
		public List<Traininggactivity> alversionquery(String trainingName) {
			List<Traininggactivity> list = traininggactivityService.filedByName(trainingName);
			return list;
		}
		// 新增
		@GetMapping("Traininggactivity_add")
		@ResponseBody
		public void definedutyEnroll( String trainingName, Timestamp trainingStarttime, Timestamp trainingEndtime,
				String trainingLocation,String certificateRemarks) {
			System.out.println(trainingName+"abc");
			traininggactivityService.traininggactivityadd(trainingName, trainingStarttime,
					trainingEndtime, trainingLocation, certificateRemarks);
		}
		// 删除
		@PostMapping("Traininggactivity_remove")
		@ResponseBody
		public void definedutyremove(Long trainingId) {
			traininggactivityService.definedutyremove(trainingId);
		}
		// 编辑
		@GetMapping("Traininggactivity_update")
		@ResponseBody
		public void TraininggactivityEdit(Long trainingId, String trainingName 
				,String trainingLocation,String certificateRemarks) {
			//System.out.println(trainingStarttime);
			// Timestamp date = new Timestamp(trainingStarttime);
			// Timestamp date1 = new Timestamp(trainingEndtime);
			traininggactivityService.traininggactivityupdate(trainingId, trainingName ,trainingLocation,certificateRemarks);
		}
		/**
		 * 培训课程安排
		 */
		@RequestMapping("Coursearrangement_pages")
		@ResponseBody
		public Map CoursearrangementPage(int page, int rows) {
			long total = coursearrangementservice.pageCount();
			List<CoursearrangementVo> list = coursearrangementservice.CoursearrangementPage(page, rows);
			Map map = new HashMap<>();
			map.put("total", total); 
			map.put("rows", list);
			return map;
		}
		@RequestMapping("Coursearrangement_yg")
		@ResponseBody
		public List<StaffInformation> Coursearrangement() {
			List<StaffInformation> list = coursearrangementservice.Coursearrangement();
			return list;
		}
			// 搜索
				@GetMapping("Coursearrangement_searchbox")
				@ResponseBody
				public List<Object[]> Coursearrangementquery(String stainName) {
					List<Object[]> list = coursearrangementservice.filedByName(stainName);
					return list;
				}
				// 清单查询
				@GetMapping("Coursearrangement_query_searchbox")
				@ResponseBody
				public List<Object[]> Coursearrangementquerysearchbox(String stainName) {
					List<Object[]> list = coursearrangementservice.filedByName1(stainName);
					return null;
				}
				
				// 新增
				@GetMapping("Coursearrangement_add")
				@ResponseBody
				public void CoursearrangementEnroll(CoursearrangementVo vo,Long stainId, String stainName,Long trainingId, String trainingName, Integer courseaQualifiedscore,
						Integer courseaTestscores,Integer courseaMakeup,Integer courseaState) {
					System.out.println(courseaMakeup+"abc"+courseaState);
					coursearrangementservice.Coursearrangementadd(vo,stainId, stainName, trainingId, trainingName,
							courseaQualifiedscore, courseaTestscores, courseaMakeup,courseaState);
				}
				// 删除
				@PostMapping("Coursearrangement_remove")
				@ResponseBody
				public void Coursearrangementremove(Long courseaId) {
					coursearrangementservice.Coursearrangementremove(courseaId);
				}
				// 编辑
				@GetMapping("Coursearrangement_update")
				@ResponseBody
				public void CoursearrangementEdit(CoursearrangementVo vo,Long courseaId,Long stainId, String stainName,Long trainingId, 
						String trainingName, Integer courseaQualifiedscore,Integer courseaTestscores,
						Integer courseaMakeup,Integer courseaState) {
					coursearrangementservice.Coursearrangementupdate(vo,courseaId, stainId,stainName,trainingId,trainingName ,courseaQualifiedscore,courseaTestscores,courseaMakeup,courseaState);
				}
				/**
				 * 培训课程列表
				 */
				@RequestMapping("Course_pages")
				@ResponseBody
				public Map CoursePage(String stainName,int page, int rows) {
					long total =courseService.pageCount();
					List<CourseVo> list = courseService.coursePage(stainName,page, rows);
					Map map = new HashMap<>();
					map.put("total", total); 
					map.put("rows", list);
					return map;
				}
				//员工查询
				@RequestMapping("Course_pages_yg1")
				@ResponseBody
				public List<StaffInformation> CoursePageyg() {
					List<StaffInformation> list = courseService.coursePageyg();
					return list;
				}
				// 新增
				@GetMapping("Course_add")
				@ResponseBody
				public void CourseEnroll(CourseVo vo) {
				System.out.println("abc"+vo.getStainName());
					 courseService.Courseadd(vo);
				}
				// 编辑
				@GetMapping("Course_update")
				@ResponseBody
				public void CourseEdit(CourseVo vo) {
					System.out.println("abcdef"+vo.getCourseStartime());
					courseService.Courseupdate(vo);
				}
				// 删除
				@PostMapping("Course_remove")
				@ResponseBody
				public void Courseremove(Long courseId) {
					courseService.Courseremove(courseId);
				}
				
				
}
